<template>
	<view class="common-container index-container">
		<view class="status_bar"> </view>
		<uni-card :is-shadow="false" is-full>
			<view class="index-top">
				<image src="../../static/logo.png" class="user-avatar"></image>
				<text class="user-info">Hi,{{userInfo.realName}},早上好！</text>
				<uni-icons type="scan" size="26" @tap="handleScan"></uni-icons>
				<uni-icons type="plusempty" size="26"></uni-icons>
			</view>
		</uni-card>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				userInfo: {}
			};
		},
		onLoad() {},
		created() {
			this.userInfo = uni.getStorageSync(this.constants.USER_INFO)
		},
		methods: {
			handleScan() {
				var $this = this
				// #ifndef H5
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log('条码res：' + res);
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						$this.$store.dispatch('scanLogin', res.result).then((res) => {
							$this.$tip.success("扫码登陆成功!")
						}).catch((e) => {
							console.log(e)
							$this.$tip.success(e)
						})
					},
					fail: function(e) {
						console.log(e)
						$this.$tip.success("二维码错误,请重新扫码!")
					}
				});
				// #endif
				// #ifdef H5
				this.$tip.alert("暂不支持")
				// #endif


			}
		}
	};
</script>

<style lang="scss">
	.index-container {
		.index-top {
			display: flex;
			flex-direction: row;

			.user-avatar {
				width: 40px;
				height: 40px;
			}

			.user-info {
				flex: 1;
				padding-left: 10px;
				line-height: 40px;
			}

			.uni-icons {
				padding-left: 8px;
				line-height: 40px;
			}
		}
	}
</style>
